import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class SocketService {
    public static void main(String[] args) throws IOException{
        SocketService socketService = new SocketService();
        socketService.oneServer();
    }
    public  void oneServer(){
        MyDC mydc=new MyDC();
        try{
            ServerSocket server=null;
            try{
                server=new ServerSocket(2222);
                System.out.println("服务器启动成功");
            }catch(Exception e) {
                System.out.println("没有启动监听："+e);
            }
            Socket socket=null;
            try{
                socket=server.accept();
            }catch(Exception e) {
                System.out.println("Error."+e);
            }
            String line;
            BufferedReader in=new BufferedReader(new InputStreamReader(socket.getInputStream()));
            PrintWriter writer=new PrintWriter(socket.getOutputStream());
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            line=in.readLine();
            int a;
            String Nline="";
            for(int i=1;i<line.length()-1;i++)
                Nline=Nline+line.charAt(i);

            System.out.println("Client:"+line);
            a=mydc.evaluate(Nline);
            System.out.println(a);
                writer.println(a);
                writer.flush();

            writer.close();
            in.close();
            socket.close();
            server.close();
        }catch(Exception e) {
            System.out.println("Error."+e);
        }
    }
}